<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ include file="/hhcommon/include/baseTop.jsp"%>
<%@ include file="/hhcommon/include/head.jsp"%>
<%@ include file="/hhcommon/include/baseBody.jsp"%>
<script type="text/javascript">
var desktoptabs = null;

function desktoptreeItemClick(data){
	if (data.leaf == false) {
		return;
	}
	var id =data.id;
	var tab = desktoptabs.getComponent(id);
	if (!tab) {
		var paramsObj = {
			vsj : data.vsj,
			title : data.text,
			id : id
		};
		var params = Ext
				.encode(paramsObj);
		var src = 'webapp-desktop-page?params='
				+ params;
		src = encodeURI(src);
		if (data.vsj.substr(0,
				3) != 'com') {
			src = data.vsj;
		} else {
			Doing.hidden(false);
		}
		var tab = null;
		if (
<%=SysParam.hhSysParam.getOnePage() == 1%>
&& data.vsj
						.substr(0, 3) == 'com') {
			tab = ExtUtil
					.create(
							data.vsj,
							{
								id : id,
								vsj : data.vsj,
								title : data.text,
								icon : data.icon,
								closable : true
							});
			desktoptabs.add(tab);
		} else if (
<%=SysParam.hhSysParam.getOnePage() == 2%>
) {
			Util.openBrowser(paramsObj);
			Doing.hidden(true);
		} else {
			var iframeHtml = '<iframe  id="iframe'
					+ id
					+ '"  name="iframe'
					+ id
					+ '"  width=100% height=100%  frameborder=0 src="'
					+ src
					+ '" ></iframe>';
			tab = desktoptabs.add({
				id : id,
				title :data.text,
				html : iframeHtml,
				icon : data.icon,
				closable : true
			});
			tab
					.on(
							'destroy',
							function() {
								var iframe = document
										.getElementById('iframe'
												+ tab.id);
								iframe.src = "about:blank";
								iframe.parentElement
										.removeChild(iframe);
							});
		}
		desktoptabs.setActiveTab(tab);
	} else {
		desktoptabs.setActiveTab(tab);
	}
}
Ext
		.onReady(function() {
			desktoptabs = Ext.widget('tabpanel', {
				region : 'center',
				activeTab : 0,
				items : {
						icon :'<%=SysParam.hhSysParam.getSysIcon()%>',
						title : '首页',
						layout:'fit',
						items : [Ext
									.create(
											"com.hh.system.desktop.HomePage")]
					},
					plugins : Ext.create('Ext.ux.TabCloseMenu', {}),
					bbar : [ '->', {
						text : '消息提醒',
						iconCls : 'user',
						handler : Desktop.onOpenMainMessage
					}, {
						text : '门户切换',
						icon : '/hhcommon/images/extjsico/undo1_16x16.gif',
						handler : function() {
							Desktop.updateDesktop('desktop');
						}
					}, {
						text : '修改主题',
						iconCls : 'hh_zt',
						handler : Desktop.onTheme
					}, {
						text : '重新登录',
						icon : '/hhcommon/images/icons/group/group_key.png',
						handler : Desktop.onAgainLogin
					}, {
						text : '身份切换',
						icon : '/hhcommon/images/icons/group/group_go.png',
						handler : Desktop.changeOrg
					}, {
						text : '个人资料',
						iconCls : 'user',
						handler : Desktop.editUser
					}, {
						text : '修改密码',
						icon : '/hhcommon/images/icons/building_key.png',
						handler : Desktop.changePassword
					}, {
						text : '退出系统',
						icon : '/hhcommon/images/icons/page/delete.png',
						handler : Desktop.onLogout
					} ]
				});

				var treeStoreData = Menu.getTreeChildrens('root');
				var store = Ext.create('com.hh.base.BaseTreeStore', {
					root : {
						children : treeStoreData
					}
				});
				var tree = Ext
						.create(
								'com.hh.base.BaseTreePanel',
								{
									region : 'west',
									title : '导航菜单',
									store : store,
									listeners : {
										itemclick : function(view, record) {
											var data = {
													leaf:	record.get("leaf"),
													id: record.get("id"),
													text:record.get("text"),
													vsj : record.raw.action,
													icon : record.raw.icon
											}
											desktoptreeItemClick(data);
										}
									},
									bbar : [ {
										iconCls : 'expand',
										text : '全部展开',
										handler : function() {
											tree.collapseAll();
											tree.expandAll();
										}
									}, {
										iconCls : 'collapse',
										text : '全部收缩',
										handler : function() {
											tree.collapseAll();
										}
									} ]
								});
				
				var systemName = '<font style="color: #596F8F; font-size: 26px;font-weight: 200; padding: 8px 15px; text-shadow: 0 1px 0 #fff;">'+document.title+'</font>';
				var systemRemark =static_var.loginuser.text
				+ " ( "
				+ static_var.loginuser.vdlzh
				+ " )&nbsp;&nbsp;&nbsp; 岗位："
				+ (static_var.currOrg.text == null
						? ""
						: static_var.currOrg.text)+'&nbsp;&nbsp;&nbsp;';
				var topHtml = '<table width="100%"><tr><td align="left">'+systemName+'</td><td  align="right">'+systemRemark+'</td></tr></table>';

				Ext.create('Ext.container.Viewport', {
					layout : 'border',
					padding : '5',
					items : [
							{
								 xtype: 'box',
								region : 'north',
								height : 40,
								html :  topHtml
							}, tree, desktoptabs ]
				});
				Login.orgChange();
				Doing.hidden(true);
			});
</script>
</html>
